package nz.ac.massey.cs.webtech.s_15273550.server;

import java.util.ArrayList;
import java.util.List;

public class Player {
    //
    private Integer money;

    public boolean isStand() {
        return stand;
    }

    public void setStand(boolean stand) {
        this.stand = stand;
    }

    private boolean stand;
    //
    private List<Card> cardsInHand;
    //
    private Integer bat;

    public Player() {
        money = 1000;
        bat = 0;
        cardsInHand = new ArrayList<Card>();
    }

    public Integer getMoney() {
        return money;
    }

    public void setMoney(Integer money) {
        this.money = money;
    }

    public List<Card> getCardsInHand() {
        return cardsInHand;
    }

    public void setCardsInHand(List<Card> cardsInHand) {
        this.cardsInHand = cardsInHand;
    }

    public Integer getBat() {
        return bat;
    }

    public void setBat(Integer bat) {
        this.bat = bat;
    }

    //
    public void showCards() {
        System.out.println("player's in hands:  points: " + getTotalPoints());
        int i = 1;
        for (Card card : cardsInHand) {
            System.out.println(i++ + "." + card.transferColor() + " " + card.transferPoint());
        }
    }

    //
    public int getTotalPoints() {
        int sum = 0;
        for (Card card : cardsInHand) {
            if (cardsInHand.size() == 2 && card.getPoint() == 1) {
                sum += 11;
            } else {
                sum += card.getPoint() > 10 ? 10 : card.getPoint();
            }
        }
        return sum;
    }

    //
    public void clear() {
        cardsInHand = new ArrayList<Card>();
    }
}


